package com.cgt.gym.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cgt.gym.pojo.Coach;
import com.cgt.gym.pojo.query.CoachQuery;
import com.cgt.gym.service.ICoachService;
import com.cgt.gym.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/coach")
public class CoachController {
	@Autowired
	private ICoachService coachService;

	@GetMapping("/list")
	public Result list(CoachQuery coachQuery) {
		System.out.println("CoachController.list");
		IPage<Coach> page = coachService.list(coachQuery);
		return Result.ok(page);

	}

	@DeleteMapping("/deleteById/{id}")
	public Result deleteById(@PathVariable Integer id) {
		coachService.removeById(id);
		return Result.ok("删除成功");
	}

	@DeleteMapping("/deleteAll/{ids}")
	public Result deleteAll(@PathVariable Integer[] ids) {
		coachService.removeBatchByIds(Arrays.asList(ids));
		return Result.ok("删除成功");
	}

	@PostMapping("/add")
	public Result add(@RequestBody Coach coach) {
		coachService.save(coach);
		return Result.ok("添加成功");
	}

	@GetMapping("/selectById/{id}")
	public Result selectById(@PathVariable Integer id) {
		Coach coach = coachService.getById(id);
		return Result.ok(coach);
	}

	@PutMapping("/update")
	public Result update(@RequestBody Coach coach) {
		coachService.updateById(coach);
		return Result.ok("修改成功");
	}
}


